package com.sslpay.merchant.service.impl;

import com.sslpay.common.domain.UploadFileException;
import com.sslpay.common.util.QiniuUtils;
import com.sslpay.merchant.service.FileService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;

/**
 * 描述：
 *
 * @author ssl
 * @create 2020/05/04 16:45
 */
@Service
public class FileServiceImpl implements FileService {

    @Value("${oss.qiniu.url}")
    private String qiniuUrl;
    @Value("${oss.qiniu.accessKey}")
    private String qiniuAccessKey;
    @Value("${oss.qiniu.secretKey}")
    private String qiniuSecretKey;
    @Value("${oss.qiniu.bucket}")
    private String qiniuBucket;

    /**
     * 上传文件
     *
     * @param file
     * @param filename
     * @return
     */
    @Override
    public String upload(byte[] file, String filename) throws UploadFileException {
        //调用common 下的工具类
        QiniuUtils.upload2qiniu(qiniuAccessKey, qiniuSecretKey, qiniuBucket, file, filename);
        return qiniuUrl.concat("/").concat(filename);
    }
}
